package top.anydata.lifeofcode.lifesystem.entity.sys.user;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;
import java.util.Objects;
import java.util.Set;

/**
 * 功能描述: 角色表
 *
 * @author <a href="mailto:caingao@anydata.top">CainGao</a>
 * @version V_1.0
 * @date 2023/8/31 5:43 PM
 */
@Data
@Entity
@Table(name = "sys_auth_role", schema = "life_system_admin", catalog = "")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SysAuthRoleEntity {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "id")
    private Integer id;
    @Basic
    @Column(name = "name")
    private String name;
    @Basic
    @Column(name = "is_deleted")
    private Byte isDeleted;
    @Basic
    @Column(name = "create_time")
    private Timestamp createTime;
    @Basic
    @Column(name = "update_time")
    private Timestamp updateTime;
    @Basic
    @Column(name = "remarks")
    private String remarks;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "sys_auth_role_permission",
            joinColumns = @JoinColumn(name = "role_id"),
            inverseJoinColumns = @JoinColumn(name = "permission_id")
    )
    private Set<SysAuthPermissionEntity> permissions;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SysAuthRoleEntity that = (SysAuthRoleEntity) o;
        return id == that.id && Objects.equals(name, that.name) && Objects.equals(isDeleted, that.isDeleted) && Objects.equals(createTime, that.createTime) && Objects.equals(updateTime, that.updateTime) && Objects.equals(remarks, that.remarks);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, isDeleted, createTime, updateTime, remarks);
    }
}
